package com.zbaohuang.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.joanzapata.android.BaseAdapterHelper;
import com.joanzapata.android.QuickAdapter;
import com.zbaohuang.activity.VolunteerActivity;
import com.zbaohuang.model.CareWarningModel;
import com.zbaohuang.model.VolunteerModel;
import com.zbaohuang.xyh.R;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class VisitorFragment extends Fragment {


    List<VolunteerModel> volunteerModels;

    QuickAdapter<VolunteerModel> quickAdapter;

    ListView listView;

    View rootView;

    public VisitorFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_visitor, container, false);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        listView = (ListView)rootView.findViewById(R.id.listview);

        volunteerModels = new ArrayList<VolunteerModel>();
        volunteerModels.add(new VolunteerModel(0));
        volunteerModels.add(new VolunteerModel(1));
        volunteerModels.add(new VolunteerModel(2));
        volunteerModels.add(new VolunteerModel(3));
        volunteerModels.add(new VolunteerModel(4));
        volunteerModels.add(new VolunteerModel(5));
        volunteerModels.add(new VolunteerModel(6));

        quickAdapter = new QuickAdapter<VolunteerModel>(getActivity(),R.layout.item_visitor) {
            @Override
            protected void convert(BaseAdapterHelper helper, VolunteerModel item) {
                switch (item.getPos()){
                    case 0:
                    {
                        helper.setImageResource(R.id.avatarImageView,R.mipmap.chenglong_big);
                        helper.setText(R.id.nameTextView, "成龙");
                        helper.setText(R.id.countTextView, "已探访:1420");
                        helper.setText(R.id.likeTextView, "3000+");
                        helper.setText(R.id.visitorDateTextView, "探访时间:2016-04-29 -- 2016-04-30");
                        helper.setText(R.id.fromTextView, "来自:红十字会");
                        helper.setText(R.id.zoneTextView,"爱心区域:中心花园，南湖小区");
                    }
                        break;
                    case 1:
                    {
                        helper.setImageResource(R.id.avatarImageView,R.mipmap.fanbingbing);
                        helper.setText(R.id.nameTextView,"范冰冰");
                        helper.setText(R.id.countTextView,"已探访:2620");
                        helper.setText(R.id.likeTextView,"5000+");
                        helper.setText(R.id.visitorDateTextView,"探访时间:2016-04-20 -- 2016-04-22");
                        helper.setText(R.id.fromTextView,"来自:中国在行动");
                        helper.setText(R.id.zoneTextView,"爱心区域:东方花园，南方家园");
                    }
                        break;
                    case 4:
                    {
                        helper.setImageResource(R.id.avatarImageView,R.mipmap.lilianjie);
                        helper.setText(R.id.nameTextView,"李连杰");
                        helper.setText(R.id.countTextView,"已探访:1620");
                        helper.setText(R.id.likeTextView,"4320+");
                        helper.setText(R.id.visitorDateTextView,"探访时间:2016-04-16 -- 2016-04-18");
                        helper.setText(R.id.fromTextView,"来自:壹基金");
                        helper.setText(R.id.zoneTextView,"爱心区域:爱康花园，朋有岛");
                    }
                        break;
                    case 6:
                    {
                        helper.setImageResource(R.id.avatarImageView,R.mipmap.yangming);
                        helper.setText(R.id.nameTextView,"姚明");
                        helper.setText(R.id.countTextView,"已探访:820");
                        helper.setText(R.id.likeTextView,"1630+");
                        helper.setText(R.id.visitorDateTextView,"探访时间:2016-04-10 -- 2016-04-13");
                        helper.setText(R.id.fromTextView,"来自:中国星行动");
                        helper.setText(R.id.zoneTextView,"爱心区域:北部湾，前海花园");
                    }
                        break;
                    case 2:
                    {
                        helper.setImageResource(R.id.avatarImageView,R.mipmap.pingming2);
                        helper.setText(R.id.nameTextView,"李敏敏");
                        helper.setText(R.id.countTextView,"已探访:220");
                        helper.setText(R.id.likeTextView,"530+");
                        helper.setText(R.id.visitorDateTextView,"探访时间:2016-04-11 -- 2016-04-15");
                        helper.setText(R.id.fromTextView,"来自:社区公益组织");
                        helper.setText(R.id.zoneTextView,"爱心区域:怡景花园，景峰台");
                    }
                    break;
                    case 5:
                    {
                        helper.setImageResource(R.id.avatarImageView,R.mipmap.xuesheng);
                        helper.setText(R.id.nameTextView,"小圆");
                        helper.setText(R.id.countTextView,"已探访:120");
                        helper.setText(R.id.likeTextView,"210+");
                        helper.setText(R.id.visitorDateTextView,"探访时间:2016-04-15 -- 2016-04-18");
                        helper.setText(R.id.fromTextView,"来自:深圳大学");
                        helper.setText(R.id.zoneTextView,"爱心区域:荔香小区，桃园小区");
                    }
                    break;
                    case 3:
                    {
                        helper.setImageResource(R.id.avatarImageView,R.mipmap.pingming1);
                        helper.setText(R.id.nameTextView,"张大卫");
                        helper.setText(R.id.countTextView,"已探访:320");
                        helper.setText(R.id.likeTextView,"530+");
                        helper.setText(R.id.visitorDateTextView,"探访时间:2016-04-20 -- 2016-04-23");
                        helper.setText(R.id.fromTextView,"来自:见义勇为基金会 ");
                        helper.setText(R.id.zoneTextView,"爱心区域:海岸花园，南山楼");
                    }
                    break;
                }
            }
        };

        listView.setAdapter(quickAdapter);

        quickAdapter.addAll(volunteerModels);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), VolunteerActivity.class);
                startActivity(intent);
            }
        });
    }

}
